import { defineConfig } from "vite";
import vue2 from "@vitejs/plugin-vue2";
import path from "path";
const isDev = process.env.NODE_ENV === "development";

export default defineConfig({
  root: isDev ? __dirname : path.resolve(__dirname, ".."),
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "../src"),
      vue: path.resolve(__dirname, "node_modules/vue/dist/vue.runtime.esm.js"),
      "vue-demi": path.resolve(__dirname, "../node_modules/vue-demi"), // 共享根目录的 vue-demi
    },
  },
  build: {
    outDir: path.resolve(__dirname, "../lib/v2.7"),
    lib: {
      entry: path.resolve(__dirname, "../src/index.js"),
      name: "weighbill-designer",
      fileName: (format) => `index.${format}.js`,
      formats: ["es", "cjs", "umd"],
    },
    rollupOptions: {
      external: ["vue", "element-ui"],
      output: {
        globals: {
          vue: "Vue",
          "element-ui": "ELEMENT",
        },
      },
    },
  },
  plugins: [vue2()],
});
